/*
   Copyright 2009 Bégaudeau Stéphane

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */

package faneclipse.editors;

import faneclipse.Activator;

import org.eclipse.core.filebuffers.IDocumentSetupParticipant;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IDocumentExtension3;
import org.eclipse.jface.text.IDocumentPartitioner;
import org.eclipse.jface.text.rules.DefaultPartitioner;



/**
 * The FanDocumentSetupParticipant is in charge of the initialization of the document.
 * @author BEGAUDEAU stephane
 */
@SuppressWarnings("deprecation")
public class FanDocumentSetupParticipant implements IDocumentSetupParticipant {
	
	/**
	 * The constructor.
	 */
	public FanDocumentSetupParticipant() {
		super();
	}
	
	/**
	 * Give a document the right partitioner.
	 * @param document The document that will be initialized.
	 * @see org.eclipse.core.filebuffers.IDocumentSetupParticipant#setup(org.eclipse.jface.text.IDocument)
	 */
	public final void setup(final IDocument document) {
		if(document instanceof IDocumentExtension3) {
			IDocumentExtension3 extension3= (IDocumentExtension3) document;
			IDocumentPartitioner partitioner= new DefaultPartitioner(FanEditor.getFanPartitionScanner(), FanPartitionScanner.FAN_PARTITION_TYPES);
			extension3.setDocumentPartitioner(Activator.FAN_PARTITIONING, partitioner);
			partitioner.connect(document);
		}
	}
}
